package com.goldsprite.projecttemplategenerator.testold;

import java.io.File;
import java.io.IOException;

public class DirectoryMover {

    public static void moveDirectory(File source, File target) throws IOException {
        if (!source.exists()) {
            throw new IOException("Source directory does not exist: " + source.getAbsolutePath());
        }

        // 创建目标目录（如果不存在）
        if (!target.exists()) {
            if (!target.mkdirs()) {
                throw new IOException("Failed to create target directory: " + target.getAbsolutePath());
            }
        }

        // 遍历源目录内容
        File[] files = source.listFiles();
        if (files != null) {
            for (File file : files) {
                File targetFile = new File(target, file.getName());
                if (file.isDirectory()) {
                    // 递归处理子目录
                    moveDirectory(file, targetFile);
                } else {
                    // 移动文件
                    if (!file.renameTo(targetFile)) {
                        throw new IOException("Failed to move file: " + file.getAbsolutePath());
                    }
                }
            }
        }

        // 删除空源目录
        if (!source.delete()) {
            throw new IOException("Failed to delete source directory: " + source.getAbsolutePath());
        }
    }

    public static void main(String[] args) {
        File source = new File("/sdcard/zzz/src/main/java/com/goldsprite/xxx/");
        File target = new File("/sdcard/zzz/src/main/java/org/aa/example/gdxapplication1");

        try {
            moveDirectory(source, target);
            System.out.println("Directory moved successfully!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

